package cn.zhc.util;

import cn.hutool.captcha.LineCaptcha;
import cn.zhc.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class CaptchaUtil {
    private LineCaptcha lineCaptcha=cn.hutool.captcha.CaptchaUtil.createLineCaptcha(200,100);
    @Autowired
    RedisService redisService;
    public String[] getImage(){
        lineCaptcha.createCode();
        String code=lineCaptcha.getCode();
        //将验证码存起来
        String key= UUID.randomUUID().toString();

        redisService.setex(key,300,code);

        String imgBase=lineCaptcha.getImageBase64();
        String[] result={key,imgBase};
        return result;
    }
//    public static void main(String[] args){
//        System.out.println(getImage());
//    }

}
